import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class Login extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return LoginState();
  }
}
class LoginState extends State{
  String account = "";
  String password = "";
  void onChangeAccount(String value){
    setState((){
      account = value;
    });

  }
  void onChangePasswprd(String value){
    setState((){
      password = value;
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Material(
      child:  Container(
        child: Column(
          children: <Widget>[
            Container(
              child:Text("登录",style: new TextStyle(fontWeight: FontWeight.normal,fontSize: 21,color: Color.fromRGBO(34, 34, 34, 1),decoration: TextDecoration.none),),
              margin: EdgeInsets.only(top: 63.5 + MediaQuery.of(context).padding.top),
            ),
            Container(
              child: TextInput(value: this.account,onChangeText: this.onChangeAccount,placeholder:"请输入账号",obscureText:false),
              color: Color.fromRGBO(248, 248, 248, 1),
              height: 44,
              width: MediaQuery.of(context).size.width - 60,
              margin: EdgeInsets.only(top:40),
            ),
            Container(
              child: TextInput(value: this.password,onChangeText: this.onChangePasswprd,placeholder:"请输入密码",obscureText:true),
              color: Color.fromRGBO(248, 248, 248, 1),
              height: 44,
              width: MediaQuery.of(context).size.width - 60,
              margin: EdgeInsets.only(top:10),
            ),
            Container(
              child:  RaisedButton(
                child: Container(
                  child:Center(child:   Text("登录",style: TextStyle(fontSize: 16,color: Color.fromRGBO(255, 255, 255, 1)),),
                  ),
                  width: MediaQuery.of(context).size.width - 60,
                  height: 44,
                ),
                color:Color.fromRGBO(6, 193, 134, 1) ,
                onPressed: (){Navigator.of(context).pushNamed('/Home');},
              ),
              margin:EdgeInsets.only(top: 10) ,
            ),
          ],
          crossAxisAlignment: CrossAxisAlignment.start,
        ),
        padding: EdgeInsets.only(left: 30,right: 30),
        decoration: new BoxDecoration(
          image:new DecorationImage(
              image: new AssetImage("lib/src/assets/image/login_background.jpg"),
              fit: BoxFit.cover,
          )
        ),
      ),
    );

  }
}

class TextInput extends StatefulWidget{
  TextInput({@required this.onChangeText,@required this.value,@required this.placeholder,@required this.obscureText});
  final onChangeText;
  final value;
  final placeholder;
  final obscureText;
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return TextInputState();
  }
}

class TextInputState extends State<TextInput>{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      child:TextFormField(
        controller: TextEditingController.fromValue(TextEditingValue(
          // 设置内容
            text: widget.value,
            // 保持光标在最后
            selection: TextSelection.fromPosition(TextPosition(
                offset: widget.value.length)))),
        decoration: InputDecoration(
          hintText: widget.placeholder,
          border:InputBorder.none,

        ),
        onChanged:widget.onChangeText,
        style: TextStyle(fontSize: 12,color: Color.fromRGBO(153, 153, 153, 1)),
          obscureText:widget.obscureText
      ),
      padding: EdgeInsets.only(left: 14.5,right: 14.5),
    ) ;
  }
}